package org.pearl.thread.demo.test002;

import java.util.concurrent.TimeUnit;

/**
 * Created by TD on 2021/4/16
 * 可见性
 */
public class VisibilityTest001 {

    public static  volatile Boolean FLAG = true;

    public static Object MUTEX=new Object();

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            while (FLAG) {
                synchronized (MUTEX){

                }
            }
        }).start();

        TimeUnit.SECONDS.sleep(3);

        new Thread(() -> {
            FLAG = false;
            System.out.println("设置FLAG为false");
        }).start();

    }
}
